package com.zxy.dao;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import com.zxy.utils.DBCPUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

public class IDNumberTopSixDao {

    public static String checkAddress(HashMap<String,String> map){
        String sql="select address from idnumbertopsix where idnumbertopsix=?";
        String address="";
    
        QueryRunner queryRunner = new QueryRunner(DBCPUtil.getDataSource());
        try {
            address = queryRunner.query(sql, new ScalarHandler<>(1),map.get("id"));
            if (address == null || address.equals("")) {
                address="查无此地";
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return address;
    }

    public static void main(String[] args) {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("id", "321284");
        String s = IDNumberTopSixDao.checkAddress(hashMap);
        System.out.println(s);
    }
}
